import { observable, action } from 'mobx';
import Api from '../../apis/monitor';
import ListBaseStore from './../ListBaseStore';

const initState = {
  loading: false,
  deleteDialogVisible: false,
};

/**
 * 邮件 - 邮件监控
 */
export default class EmailMonitorLogStore extends ListBaseStore {
  @observable loading = initState.loading;
  @observable deleteDialogVisible = initState.deleteDialogVisible;

  @action setState = (params = {}) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
    return this;
  };

  /**
   * 显示或隐藏监控日志
   */
  @action showMonitorLogDialog = (mode) => {
    this.setState({
      deleteDialogVisible: mode,
    });
    if (mode) {
      this.doTableLoading();
    }
  };

  // 加载列表数据
  @action doTableLoading = (params) => {
    this.showLoading(true);
    let resultParams = this.getFormParams();
    let commonParams = {};
    resultParams = { ...resultParams, ...commonParams, ...params };

    Api.monitorLogList(resultParams).then((result) => {
      this.viewRight = result.viewRight == 1;
      if (this.viewRight) {
        const sessionkey = result.sessionkey;
        this.sessionkey = sessionkey;
        this.comsWeaTableStore.getDatas(sessionkey, 1);
      }

      this.setViewRightInitCompleted(); // 要放在后面，防止有权限时，初始化慢导致无权限提示闪一下

      this.showLoading(false);
    });
  };

  // 初始化收藏的帖子页面查询条件
  @action initConditionDatas = (params) => {
    Api.monitorLogCondition(params).then((result) => {
      this.conditioninfo = result.conditioninfo;

      this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
    });
  };
}
